//
//  SHStatusViewModel.swift
//  weibo1
//
//  Created by TownFish on 16/7/31.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit
//该viewModel 为cell (原创微博转发微博和底部视图)服务
class SHStatusViewModel: NSObject {
    
    //定义一个属性
    var status: SHStatus?
    //微博认证用户图片
    var avatarImage: UIImage?
    //处理会员等级图片
    var memberImage: UIImage?
    
    //重载构造函数
    init(status: SHStatus) {
        super.init()
        self.status = status
        //在viewModel调用重载构造函数初始化的时候,我们要对avatarImage和memberImage 赋值
        self.avatarImage = getAvatarImage(status.user?.verified)
        self.memberImage = getMemberImage(status.user?.mbrank)
//        print("重载赋值")
    }
}

//MARK: - 数据处理
extension SHStatusViewModel {
    //处理微博认证用户图片
    // 认证类型 -1：没有认证，1，认证用户，2,3,5: 企业认证，220: 达人
    func getAvatarImage(verified: Int?) -> UIImage? {
//        print("处理微博认证用户图片")
        //判断他是否为nil
        guard let ver = verified else {
            return nil
        }
        switch ver {
        case 1:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_enterprise_vip")
        case 220:
            return UIImage(named: "avatar_grassroot")
        default:
            return UIImage(named: "avatar_vgirl")
        }
    }
    
    
    
    
    
    //处理会员等级 会员等级 1-6
    func getMemberImage(mbrank: Int?) ->UIImage? {
//        print("处理会员等级图片")
        //判断他是否为nil
        guard let mbr = mbrank else {
            return nil
        }
        if mbrank > 0 && mbr < 7{
            return UIImage(named: "common_icon_membership_level\(mbr)")
        }
        return UIImage(named: "common_icon_membership")
    }
}